﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Linq;
using MMMigrator.ClassLibrary;

namespace MMMigrator.Exporter
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initialise
            XElement output = null;
            string siteCollection = args[0];
            string groupName = args[1];
            string targetPath = args[2];

            // Perform Generation
            try
            {
                output = ExportMetadata.GenerateExportXML(siteCollection, groupName);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                //Console.ReadLine();
                Environment.Exit(1);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine("The Group Name could not be found:");
                Console.WriteLine(ex.Message);
                //Console.ReadLine();
                Environment.Exit(1);
            }

            // Save to file system
            try
            {
                StreamWriter sw = new StreamWriter(targetPath + @"\\MMM_Output.xml");
                sw.Write(output.ToString());
                sw.Close();
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
    }
}
